package sis.ui;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-08-04 17:36
 * @notify
 * @version 1.0
 */

import javax.swing.*;
import java.awt.*;

public class Util {

    //给定容器,和组件名,查询容器小是否有该组件
    public static Component getComponent(Container container, String name) {
        for (Component component : container.getComponents()) {
            if (name.equals(component.getName())) {
                return component;
            }
            if (component instanceof Container) {
                Container subcontainer = (Container) component;
                Component subcomponent = getComponent(subcontainer, name);
                if (subcomponent != null) {
                    return subcomponent;
                }
            }
        }
        return null;
    }

    //给定窗体,和组件名字,查询窗体下有没有指定组件
    public static Component getComponent(JFrame frame, String name) {
        return getComponent(frame.getContentPane(), name);
    }
}
